from django.shortcuts import render

from django.db import models
from django.contrib.postgres.fields import ArrayField
# Create your views here .
'''# CHANGELOG
1. 将idmi抓取的 dongchedi / autohome的数据单独的存储起来
'''
class IdmiCuZuModel(models.Model) :
    '''
    存储 IDMI CuZu 的主数据
    '''
    sourceId_choices = (
        ('autohome', 'autohome'),
        ('dongchedi', 'dongchedi')
    )
    id = models.AutoField(primary_key=True)
    create_time = models.DateTimeField(
        verbose_name="create_time",
        editable=True
    )
    URL = models.CharField(
        max_length=400,
        verbose_name='URL',
        null=True,
        blank=True,
        default=''
    )
    address = models.CharField(
        max_length=100,
        verbose_name='address',
        null=True,
        blank=True,
        default=''
    )
    boughtdate = models.CharField(
        max_length=15,
        verbose_name='boughtdate',
        null=True,
        blank=True,
        default=''
    )
    carspec_name = models.CharField(
        max_length=50,
        verbose_name='carspec_name',
        null=True,
        blank=True,
        default=''
    )
    title_zh = models.CharField(
        max_length=500,
        verbose_name='title',
        null=True,
        blank=True,
        default=''
    )
    customer_voice_zh = models.TextField(
        max_length=5000,
        verbose_name='customer_voice',
        null=True,
        blank=True,
        default=''
    )
    title_en = models.CharField(
        max_length=1000,
        verbose_name='title',
        null=True,
        blank=True,
        default=''
    )
    customer_voice_en = models.TextField(
        max_length=10000,
        verbose_name='customer_voice',
        null=True,
        blank=True,
        default=''
    )
    image_url = models.CharField(
        max_length=400,
        verbose_name='image_url',
        null=True,
        blank=True,
        default=''
    )
    price = models.CharField(
        max_length=20,
        verbose_name='price',
        null=True,
        blank=True,
        default=''
    )

    website = models.CharField(
        max_length=50,
        verbose_name='website',
        choices=sourceId_choices,
        default='autohome'
    )

    url_temp = models.CharField(
        max_length=400,
        verbose_name='url_temp',
        null=True,
        blank=True,
        default=''
    )
    src_bought_date = models.CharField(
        max_length=50,
        verbose_name='src_bought_date',
        null=True,
        blank=True,
        default=''
    )
    series_id = models.CharField(
        max_length=50,
        verbose_name='series_id',
        null=True,
        blank=True,
        default=''
    )
    src_series_name = models.CharField(
        max_length=50,
        verbose_name='src_series_name',
        null=True,
        blank=True,
        default=''
    )
    BodyType = models.CharField(
        max_length=50,
        verbose_name='BodyType',
        null=True,
        blank=True,
        default=''
    )
    Brand = models.CharField(
        max_length=50,
        verbose_name='Brand',
        null=True,
        blank=True,
        default=''
    )
    BrandIndicator = models.CharField(
        max_length=50,
        verbose_name='BrandIndicator',
        null=True,
        blank=True,
        default=''
    )
    FuelType = models.CharField(
        max_length=50,
        verbose_name='FuelType',
        null=True,
        blank=True,
        default=''
    )
    Group = models.CharField(
        max_length=50,
        verbose_name='Group',
        null=True,
        blank=True,
        default=''
    )
    OEM = models.CharField(
        max_length=50,
        verbose_name='OEM',
        null=True,
        blank=True,
        default=''
    )
    ModelName = models.CharField(
        max_length=50,
        verbose_name='ModelName',
        null=True,
        blank=True,
        default=''
    )
    Segment = models.CharField(
        max_length=50,
        verbose_name='Segment',
        null=True,
        blank=True,
        default=''
    )
    fid = models.IntegerField(
        default=0
    )

    def __str__(self):
        return self.id

    class Meta:
        db_table = 'idmicuzu'
        verbose_name = 'idmicuzu'
        ordering = ['-id']
        abstract = False


class IdmiCuZuResModel(models.Model) :
    '''
    存储 IDMI CuZu 的结果数据
    '''
    # id = models.AutoField(primary_key=True)
    cuzu = models.ForeignKey(
        to=IdmiCuZuModel,
        on_delete=models.CASCADE,
        verbose_name='cuzu_res',
        related_name='cuzu_res'
    )
    cuzu_label_1_int_value = models.IntegerField(
        verbose_name='cuzu_label_1_int_value',
        null=True,
        blank=True,
        default=-1
    )
    cuzu_label_2_int_value = models.IntegerField(
        verbose_name='cuzu_label_2_int_value',
        null=True,
        blank=True,
        default=-1
    )
    content_list_zh = ArrayField(
        models.CharField(
            max_length=500,
            verbose_name='content_list_zh',
            null=True,
            blank=True,
            default=''
        )
    )
    content_list_en = ArrayField(
        models.CharField(
            max_length=500,
            verbose_name='content_list_en',
            null=True,
            blank=True,
            default=''
        )
    )
    sentiment = models.IntegerField(
        verbose_name='sentiment',
        choices=[
            (1, 1),
            (2, 2),
            (3, 3),
            (4, 4),
            (5, 5),
        ],
        default=3
    )
    def __str__(self):
        return f"{self.cuzu.id}"

    class Meta:
        db_table = 'idmicuzures'
        verbose_name = 'idmicuzures'
        ordering = ['-id']
        abstract = False

